import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

months = ["11月", "12月"]
sales = [664, 727]
change_rate = 9.49

# 颜色设置
colors = ['#4F81BD', '#6DCFF6']

# 创建图表
plt.figure(figsize=(8, 4), facecolor='#2E4057')
ax = plt.gca()
ax.set_facecolor('#2E4057')

# 绘制水平条形图
bars = plt.barh(months, sales, color=colors, height=0.4, edgecolor='none')

# 添加数值标签
for i, bar in enumerate(bars):
    # 条形图右侧显示销售值
    plt.text(bar.get_width() + 10, bar.get_y() + bar.get_height() / 2,
             f"{sales[i]}", va='center', ha='left', fontsize=22, color='white')

# 显示变化率文本
plt.text(max(sales) + 100, bars[1].get_y() + bars[1].get_height() / 2,
            f"{change_rate:.2f}%", ha='left', va='center', fontsize=22, color='white', weight='bold')
plt.text(max(sales) + 100, bars[0].get_y() + bars[0].get_height() / 2,
            "同比", ha='left', va='center', fontsize=22, color='white')

# 设置标题
plt.title("销量环比", fontsize=20, color='white', pad=20)

# 设置左侧月份字体大小
plt.yticks(fontsize=25, color='white')

# 隐藏坐标轴
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.tick_params(left=False, bottom=False, labelleft=True, labelbottom=False)

# 调整布局
plt.tight_layout()

plt.savefig(r'D:\python charm\01\可视化\销售看板参考\图片\月同比增长.png')

plt.show()